package main

import (
	"flag"
	"fmt"
	"github.com/rs/zerolog/log"
	"path/filepath"
	"shyxy-net/gateway/application"
	"shyxy-net/gateway/config"
	"shyxy-net/gateway/http"
)

var configDir = flag.String("config_dir", "./config", "config dir: default value is ./config")
var configFile = flag.String("config_file", "config.json", "config file: default value is config.json")

func main() {
	flag.Parse()
	configPath := filepath.Join(*configDir, *configFile)
	cfg, loadConfigErr := config.Loading(configPath)
	if loadConfigErr != nil {
		panic(loadConfigErr)
	}

	app, err := application.New(cfg)
	if err != nil {
		log.Error().Msgf("error during App Construction,err:%s", err)
	}
	appHTTP, err := http.API(app)
	if err != nil {
		log.Error().Msgf("error during HTTP App Construction,err:%s", err)
	}
	port := cfg.ApplicationConfig.Port
	if err = appHTTP.Listen(fmt.Sprintf(":%d", port)); err != nil {
		log.Error().Msgf("error during HTTP App Listen,err:%s", err)
	}

}
